<?php
	/**
	 *	Copyright (c) TeamFlamingo And gray 2004-2009
	 *	www.me-live.com.cn / www.i-gray.cn
	 *
	 *	[ WARNING ]
	 *		This is NOT a freeware!
	 *		You MUST get author's authorization before using it!
	 *	[ WARNING ]
	 *
	 *	Name : weather.php / Development Code Evolve
	 *	Created / Modify : 2010-2-15 / --
	 */
	include	'../init.php';

	$data	=	$url	=	$todayUnixTime	=	$yesterdayUnixTime	=	null;
	$tempArr	=	array();

	/**
	 *	这里还要做一个Ajax请求的判定
	 */

	if( !is_dir( ME_CACHE_DIR ) )
	{
		@mkdir( ME_CACHE_DIR, 0777 );
	}

	$todayUnixTime	=	mktime( 0, 0, 0, date( "m" ), date( "d" ), date( "Y" ) );

	if( !file_exists( ME_WEATHER_CACHE ) || filemtime( ME_WEATHER_CACHE ) < $todayUnixTime )
	{
		$url	=	'http://weather.news.qq.com/inc/ss69.htm';
		$data	=	trim( @file_get_contents( $url ) );
		$data	=	preg_replace( "/\s{2,}/", '', $data );
		$data	=	preg_replace( "/<style[^>]*?>.*?<\/style>/is", '', $data );
		$data	=	preg_replace( "/<script[^>]*?>.*?<\/script>/is", '', $data );
		$data	=	preg_replace( "/<select[^>]*?>.*?<\/select>/is", '', $data );
		$data	=	strip_tags( $data, '<td>' );
		$data	=	preg_replace( "/<(|\/)\w[^>]*?>/is", '', $data );
		$data	=	preg_replace( "/\s+/", ' ', $data );

		$tempArr	=	split( ' ', iconv( 'gb2312', 'utf-8', trim( $data ) ) );
		$cacheFile	=	"<?php\n\tif( !defined( 'IN_TEAME' ) )\n\t{\n\t\texit( 'Access Denied' );\n\t}\n\t\$weather\t=\tarray('{$tempArr[1]}', '{$tempArr[2]}', '{$tempArr[3]}');\n?>";
		@file_put_contents( ME_WEATHER_CACHE, $cacheFile );
		//echo	'create new file source';
	}

	include	ME_WEATHER_CACHE;
	//	[CH]	改变一下天气信息格式
	//echo	"['{$weather[0]}','{$weather[1]}','{$weather[2]}']";
	echo	"{$weather[0]}|{$weather[1]}|{$weather[2]}";
?>